function Ajax() {}
//data  表示请求的参数
//url   要发送的地址
//callback  回调函数
Ajax.prototype.get = function(url,data,callback) {
    var http = new XMLHttpRequest();
    // 下面这个方法可以让对字符串进行自动转换
    http.responseType = 'json'
    http.open('GET',url);
    url+='?';
    for(var i in data){ 
        url+=i
        url+="="+data[i]+'&'
    }
    url = url.substring(0, url.lastIndexOf('&'));
    console.log(url)
    http.send();
    http.onreadystatechange= function(){
        if(http.readyState === 4&http.status === 200) {
            if(callback) {
                callback(http.response);
            }
        }
    }
}
Ajax.prototype.post = function(url,data,callback){
    var xhr = new XMLHttpRequest();
    xhr.open('POST',url)
    xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded')
    var stamen="";
    for(var i in data){ 
        stamen +=i
        stamen +="="+data[i]+'&'
    }
    stamen = stamen.substring(0, stamen.lastIndexOf('&'));
    xhr.send(stamen)
    xhr.onreadystatechange=function() {
        if(xhr.readyState === 4 && xhr.status === 200){
            if(callback) {
                callback(xhr.response)
            }
        }
    }
}